//
//  Date+Extension.swift
//  Story
//
//  Created by 汤泽川 on 2019/5/4.
//  Copyright © 2019 汤泽川. All rights reserved.
//

import Foundation

extension Date {
    var natureFormat: String {
        let currentTime = Date().timeIntervalSince1970
        let timeSta : TimeInterval = self.timeIntervalSince1970
        let reduceTime : TimeInterval = currentTime - timeSta
        if reduceTime < 60 {
            return "刚刚"
        }
        let mins = Int(reduceTime / 60)
        if mins < 60 {
            return "\(mins)分钟前"
        }
        let hours = Int(reduceTime / 3600)
        if hours < 24 {
            return "\(hours)小时前"
        }
        let days = Int(reduceTime / 3600 / 24)
        if days < 30 {
            return "\(days)天前"
        }
        let date = NSDate(timeIntervalSince1970: timeSta)
        let dfmatter = DateFormatter()
        dfmatter.dateFormat="yyyy年MM月dd日 HH:mm:ss"
        return dfmatter.string(from: date as Date)
    }
}
